package com.bt.lms.ui.action.school_education.stu_basic.BasicMes;

import javafx.collections.ObservableList;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.Node;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.stage.FileChooser;

import java.io.File;

/**
 * 学员信息管理里的修改头像功能事件
 * 头像为one里脚标为4的位置
 */
public class BasicMesAmendPhoto implements EventHandler {

    private VBox one;

    private static double size = 1;
    private static double count = 1.0;

    public BasicMesAmendPhoto(VBox one) {
        this.one = one;
    }

    @Override
    public void handle(Event event) {
        FileChooser fileChooser = new FileChooser();
        File file = fileChooser.showOpenDialog(null);
        BasicMesEditAction.file = file;

        VBox six = new VBox();
        six.setPrefWidth(300);
        Pane pane = new Pane();
        pane.setPrefHeight(100);
        pane.setMaxWidth(100);
        String path = String.valueOf(file);
        String url = "file:"+File.separator + path;
        Image image = new Image(url);
        ImageView imageView = new ImageView(image);
        imageView.setFitWidth(100);
        imageView.setFitHeight(100);
        pane.getChildren().add(imageView);
        six.getChildren().add(pane);

        ObservableList<Node> children = one.getChildren();
        children.set(0,six);


        size = 1;
        count = 1;
        imageView.setOnScroll(event1 -> {
            if (event1.getDeltaY() > 0) {
                count = count + 1.0 / 10;
                size = 1.0 / 200 * (count - 1) * (count - 1) * (count - 1) + 1;
                imageView.setFitWidth(imageView.getFitWidth() * size);
                imageView.setFitHeight(imageView.getFitHeight() * size);
                count++;
            } else {
                count = count - 1.0 / 10;
                double y = 1.0 / 200 * (count - 1) * (count - 1) * (count - 1) + 1;
                size = y < 0 ? size : y;
                imageView.setFitWidth(imageView.getFitWidth() / size);
                imageView.setFitHeight(imageView.getFitHeight() / size);
                count--;
            }
        });



    }
}
